﻿using FreeSql;
using FreeSql.DataAnnotations;
using System;
using System.Linq.Dynamic.Core;
using System.Linq.Expressions;

var fsql = new FreeSqlBuilder()
                 .UseConnectionString(DataType.MySql, "Server=localhost;Database=mlmw;charset=utf8;user=root;password=root")
                 .UseAutoSyncStructure(true)
                 .Build();

//定义一个expression
Expression<Func<MyEntity, string>> newexp = x => x.Name;

//使用System.Linq.Dynamic.Core 包装成另一个expression
var func = DynamicExpressionParser.ParseLambda<MyEntity, bool>(new ParsingConfig(), true, "@0(it)==\"aa\"", new[] { newexp });

//报错variable '' of type 'MyEntity' referenced from scope '', but it is not defined
var a = fsql.Select<MyEntity>().Where(func).Count();

internal class MyEntity
{
    [Column(IsIdentity = true)]
    public int Id { get; set; }

    public string Name { get; set; }
}